------------------------【三十二秒散件黑人奥陨老年人连猜带蒙定制版-V1.9】------------------------
---【																		   】
---【检查调整config中的start,hr_start启动键,默认G5神目黑人陨石启动,G4黑人陨石启动(续黑人,不常用)   】
---【检查调整config.force_stand_key强制站立,默认为空格(spacebar),force_move_key强制移动键w     】
---【检查调整改skills中的技能按键数字1-6,对应技能栏顺序按键								   】
---【关闭宏默认按capslock、可添加该命令拖到习惯键位上									   】
---【默认开启陨石后踩神目,需要在神目陨石后的1.5秒(原手动踩神目时间)内按住ctrl标记,标记成功鼠标会归位  】
---【伤害不稳调整config.delay(31行)和skills.sx.hr_delay(43行)							   】
---【尽量多叠勾玉早开宏 × 3,怪物太多可能会卡掉黑人技能	 				  				   】
---【使用前先看完注释   × 3	 				   									   】

--常量表
constant = {
	f			=    1000/60,								--帧
	hr_time		=    20000,								--黑人周期	
	br_time		=    12000,								--白人周期
	cycle_time	=    32000,								--循环周期
	ys_time		=    1250	,								--陨石时间
	window_center = 	{x=65535/2, y=65535/2},				--屏幕中心位置
};
--脚本启动配置
config = {
	start			= 5,									--神目黑人陨石启动 默认G5 冰1.5-火0.5开
	hr_start			= 4,									--黑人陨石启动 默认G4 电0.5-电3.5开
	speed			= 1.75,								--满勾玉攻速
	on_off   			= "capslock",							--开关指示灯
	force_stand_key 	= "spacebar",							--强制站立键位,老李请改为lshift
	force_move_key 	= "w",								--强制移动键位
	check_close_time 	= 200,								--检查关闭宏间隔(ms)
	avert_0hd_time    	= 1500,								--预防0层黑洞延迟,后接skills.dx.sm_delay电刑时间
	delay   		 	= constant.f * 2,						--延迟帧数,增加/减少该值可推迟/提前引导 
	auto_csm			= true,								--自动踩神目开关，鼠标移动到神目圈按ctrl标记,必须在第二发黑洞前的电刑前标记
	db_count			= 30,								--赌博次数
	debug			= true								--调试开关 true打开 false关闭
};
--技能按键及延迟配置,5、6对应左右键,以下固定部分延迟取自1.54攻速下的,不影响循环,可自行修改为满勾玉1.75下的,0值修改无效
skills = {
	ylb   = {key="1", delay=633.33},							--原力波
	dx    = {key="5", delay=1350, sm_delay=600, ys_delay=0},		--电刑
	yss   = {key="3", delay=(60/config.speed) * 0.35 * constant.f},	--陨石
	sx    = {key="6", delay=2 * 17 * constant.f, 
					hr_delay=constant.f * 3},					--冰霜射线,hr_delay为引导后多久变黑
	hd    = {key="4", delay=633.333},							--黑洞
	hr    = {key="2", delay=constant.f * 0},						--黑人, 不建议放1键位	
	sdcj  = {key="1", delay=700}								--黑人变身1技能 固定key=1，不可更改
};
--变量表
vars = {
	start_at 				= 	0,								--脚本开启时间
	hr_start_at 			= 	0,								--黑人开启时间
	current_cycle_start_at = 	0,								--当前轮循环开始时间
	execute_count 		= 	0,								--总循环次数
	cycle_delay 			= 	0,								--每次循环结束延迟
	total_dealy 			= 	0,								--总延迟
	sleep_count			=	0,								--休眠次数
	sleep_time			=	0,								--休眠时间(余数)
	br_wait_time			=	0,								--白人开始等待时间
	hr_delay				=   	0,								--黑人结束等待时间
	last_mouse_at      	=	{x=0, y=0},						--上次鼠标位置	
	mouse_move_to      	=	{x=0, y=0},						--鼠标移动目标位置
	need_csm				=	false 							--是否需要自动踩神目
};

--按键响应函数
function OnEvent(event, arg)
	if (event == "MOUSE_BUTTON_PRESSED") then
		Sleep(config.check_close_time);
		if arg == config.start then								--神目黑人启动	
			SM_YS();											--神目陨石
			HR_YS();											--黑人陨石
			KEEP_HR_GY();										--黑人保持勾玉
			HR_AO_YUN_CYCLE();									--黑人奥陨循环	
		elseif arg == config.hr_start then						--黑人陨石启动	
			HR_YS();											--黑人陨石
			KEEP_HR_GY();										--黑人保持勾玉
			HR_AO_YUN_CYCLE();									--黑人奥陨循环
		elseif (arg == 2 and (not IsKeyLockOn("capslock")) and IsModifierPressed("ctrl")) then
			AUTO_DB();										--一键赌博左ctrl+右键
		else
			-- 其他功能	
		end
	end	
	vars.execute_count = 0;
	vars.total_dealy = 0;
	vars.need_csm = false;
	
end
--黑人奥陨循环
function HR_AO_YUN_CYCLE()
	while(IsKeyLockOn(config.on_off)) do
		vars.start_at = GetRunningTime();
		PressWithDelayAndRelease(skills.dx, vars.br_wait_time - vars.total_dealy);
		SM_YS();
		HR_YS();
		KEEP_HR_GY();
		vars.execute_count = vars.execute_count + 1;
		vars.total_dealy = GetRunningTime() - constant.cycle_time - vars.start_at;
	end
end
--神目陨石
function SM_YS()
	PressAndReleaseWithDelay(skills.hd,  skills.hd.delay);
	PressAndReleaseWithDelay(skills.ylb, skills.ylb.delay);
	PressWithDelayAndRelease(skills.dx,  skills.dx.delay);
	PressWithDelayAndRelease(skills.yss, skills.yss.delay);
	PressWithDelayAndRelease(skills.dx,  skills.dx.ys_delay - constant.f * 8);
	SleepWithCheckSwitch(constant.f * 8);
	PressWithDelayAndRelease(skills.sx,  skills.sx.delay);
	if(config.auto_csm) then
		SleepWithCheckSwitchAndCSM(config.avert_0hd_time);
	else
		SleepWithCheckSwitch(config.avert_0hd_time);
	end
	PressWithDelayAndRelease(skills.dx,  skills.dx.sm_delay);
end
--黑人陨石
function HR_YS()
	PressAndReleaseWithDelay(skills.hd,  skills.hd.delay);
	PressAndReleaseWithDelay(skills.ylb, skills.ylb.delay);
	PressWithDelayAndRelease(skills.dx,  skills.dx.delay);
	PressAndReleaseWithDelay(skills.yss, skills.yss.delay);
	if(config.auto_csm and vars.need_csm) then
		vars.need_csm = false;	
		MoveMouseTo(vars.mouse_move_to.x, vars.mouse_move_to.y);
		PressAndReleaseKey(config.force_move_key);
		SleepWithCheckSwitch(skills.dx.ys_delay + config.delay);
	else
		PressWithDelayAndRelease(skills.dx,  skills.dx.ys_delay + config.delay - constant.f * 8);
		SleepWithCheckSwitch(constant.f * 8);
	end
	if not IsKeyLockOn(config.on_off) then return; end
	skills.sx.PressKey(skills.sx.key);
	Sleep(skills.sx.hr_delay);
	PressWithDelayAndRelease(skills.hr, skills.hr.delay);
	Sleep(20 * constant.f);
	skills.sx.ReleaseKey(skills.sx.key);
end
--黑人保持勾玉
function KEEP_HR_GY()
	vars.hr_start_at = GetRunningTime();
	SleepWithCheckSwitch(skills.sdcj.delay); 
	for i=1, constant.sdcj_count, 1 do 
		if not IsKeyLockOn(config.on_off) then return; end
		PressAndReleaseWithDelay(skills.sdcj, skills.sdcj.delay);
	end
	vars.hr_delay = constant.hr_time - GetRunningTime() + vars.hr_start_at;
	SleepWithCheckSwitch(vars.hr_delay);
end
--赌博功能
function AUTO_DB() 
	PressAndReleaseKey("capslock");
	Sleep(100);
	ReleaseKey("lctrl");
	for i=1, config.db_count, 1 do
		PressAndReleaseMouseButton(3);
		Sleep(10);
	end
	PressAndReleaseKey("capslock");
	Sleep(100);
end

function PressAndReleaseWithDelay(skill, delay)
	if not IsKeyLockOn(config.on_off) then return; end
	if skill.forceStand then PressKey(config.force_stand_key); end
	skill.PressAndReleaseKey(skill.key);
	SleepWithCheckSwitch(delay);
	if skill.forceStand then ReleaseKey(config.force_stand_key); end
end

function PressWithDelayAndRelease(skill, delay)
	if not IsKeyLockOn(config.on_off) then return; end
	if skill.forceStand then PressKey(config.force_stand_key); end
	skill.PressKey(skill.key);
	SleepWithCheckSwitch(delay);
	skill.ReleaseKey(skill.key);
	if skill.forceStand then ReleaseKey(config.force_stand_key); end
end

function SleepWithCheckSwitch(delay)
	vars.sleep_count, vars.sleep_time = math.modf(delay/config.check_close_time);
	while(IsKeyLockOn(config.on_off) and vars.sleep_count > 0) do
		Sleep(config.check_close_time);
		vars.sleep_count = vars.sleep_count -1;
	end
	if(IsKeyLockOn(config.on_off) and vars.sleep_time > 0) then 
		Sleep(vars.sleep_time * config.check_close_time);
	end
end

function SleepWithCheckSwitchAndCSM(delay)
	vars.sleep_count, vars.sleep_time = math.modf(delay/config.check_close_time);
	--if skills.dx.forceStand then PressKey(config.force_stand_key); end
	--skills.dx.PressKey(skills.dx.key);
	while(IsKeyLockOn(config.on_off) and vars.sleep_count > 0) do
		Sleep(config.check_close_time);
		vars.sleep_count = vars.sleep_count -1;
		if(IsModifierPressed("ctrl") and not vars.need_csm) then
			vars.need_csm = true;
			vars.mouse_move_to.x, vars.mouse_move_to.y = GetMousePosition();
			MoveMouseTo(constant.window_center.x, constant.window_center.y);
		end
	end
	if(IsKeyLockOn(config.on_off) and vars.sleep_time > 0) then 
		Sleep(vars.sleep_time * config.check_close_time);
	end
	--skills.dx.ReleaseKey(skills.dx.key);
	--if skills.dx.forceStand then ReleaseKey(config.force_stand_key); end
end

function Debug(msg, ...)
	if config.debug then
		OutputLogMessage(msg, ...);
	end
end

(function () 
	for k,v in pairs(skills) do
		local tempKey = v.key;
		v.PressKey = PressKey;
		v.ReleaseKey = ReleaseKey;
		v.PressAndReleaseKey = PressAndReleaseKey;
		v.forceStand = false;
     	if tempKey == "5" or tempKey == "6" then 
			v.PressKey = PressMouseButton;
			v.ReleaseKey = ReleaseMouseButton;
			v.PressAndReleaseKey = PressAndReleaseMouseButton;
			v.key = (tempKey == "5" and 1 or 3);
			v.forceStand = (tempKey == "5" and true or false);
		end
	end
	constant.sdcj_count = math.modf(constant.hr_time / skills.sdcj.delay) - 1;
	skills.dx.ys_delay = constant.ys_time - skills.sx.delay / 2 ;
	local sm_ay_time = skills.hd.delay + skills.ylb.delay + skills.dx.delay + skills.yss.delay + 
					 skills.dx.ys_delay + skills.sx.delay + config.avert_0hd_time + skills.dx.sm_delay;
	local hr_ay_time = skills.hd.delay + skills.ylb.delay + skills.dx.delay + skills.yss.delay + 
					 skills.dx.ys_delay + config.delay +skills.sx.hr_delay + skills.hr.delay + 20 * constant.f;
	vars.br_wait_time = constant.br_time - sm_ay_time - hr_ay_time;
end)();
---【感谢队友鼹鼠、BossVC、aBc、上善若水,另外向一直战斗在一线的老年人同时也是本宏功能、建议的提出者jackli致敬】---
----------------------------------【祝大家游戏愉快. 2019.3.26. GMTSTU】---------------------------------